import { mapActions } from 'vuex'
export default {
    name: 'user',
    data() {
        return {
            users: [],
            userDatas: [
                { name: '用户1', img: '/static/img/01.png', phone: '13636898669', starttime: '2017年02月15日', integral: '88' }
            ],
            pageSizeNum: 10,
            totalNum: 0,
            loading: false
        }
    },
    created: function() {
        // 判断用户是否登录
        var userId = sessionStorage.getItem('userId')
        if (!userId) {
            var warningStr = "没有登录不允许访问该页面,点击确定跳转登录页面"
            this.$alert(warningStr, '提示', {
                confirmButtonText: '确定',
                type: 'warning'
            }).then(() => {
                this.$router.push({
                    path: '/login'
                })
            }).catch(() => {
                this.$router.push({
                    path: '/login'
                })
            });
        }
        // 初始化分页
        var pageLists = this.userDatas;
        var page = this.pageSizeNum
        this.users = pageLists.slice(0, page)
        this.totalNum = pageLists.length
            // 获取所有用户
        var self = this;
        self.loading = true
        this.getUserAll({}).then((data) => {
            console.log(data)
            if (data.data.code == "200") {
                // self.loading = false
                // var pageLists = data.data.data.reverse();
                // self.admins = pageLists
                // var page = self.pageSizeNum
                // self.items = pageLists.slice(0, page)
                // self.totalNum = pageLists.length
            }
        }).catch(msg => console.log(msg))
    },
    methods: {
        // 设置每页个数
        handleSizeChange(val) {
            var pageLists = this.userDatas
            this.pageSizeNum = val;
            this.users = pageLists.slice(0, val)
        },
        // 点击分页
        handleCurrentChange(val) {
            var pageLists = this.userDatas;
            var page = this.pageSizeNum
            var startPage = (val - 1) * page
            var endPage = val * page
            this.users = pageLists.slice(startPage, endPage)
        },
        ...mapActions(['getUserAll']), // 注册
        // ...mapActions(['getAdmins']),// 返回管理员列表
    }
}
this.isSadeNacClo = 2
break;
case 'harness':
    this.isSadeNacClo = 1
    break;
case 'user':
    this.isSadeNacClo = 0
    break;
default:
    break;
    }
    },
    methods: {
        // 侧栏导航切换
        sadeNavClick(index) {
            this.isSadeNacClo = index
            var pathStr = this.lists[index].push
            var url = '/home/' + pathStr
            this.$router.push({
                path: url
            })
        },
        // 管理操作
        backHomeClick() {
            this.isNavPopup = !this.isNavPopup;
        },
        // 退出界面
        backHome() {
            sessionStorage.removeItem('userId')
            this.$router.push({
                path: '/login'
            })
        }
    }
    }